#include "stdtypedef.h"
#include "system.h"
#include "drv_pwm.h"


void init_pwm(void){
    PR2 = 128;              //Max Period [100+1]*4*1/Fosc*Preescaler
    T2CON = 0b00000100;     //TMR2 ON, Preescaler 1:1
    CCP2CON = 0b00001100;   //PWM mode
}


void set_pwm(T_UBYTE lub_value,T_UBYTE lub_channel){
    volatile T_UBYTE lub_Aux;
    switch(lub_channel){
        case 1:
            /*
            lub_Aux = CCP1CON;
            CCP1CON = ((lub_Aux & ~(0b11 << 4)) | ((lub_value & 0b11) << 4));
             */
            CCPR1L = (lub_value);// & ~(0b11)) >> 2;
            break;
        case 2:
            CCPR2L = (lub_value);
            break;
        default:
            break;
    }
}
